package vn.allmobile.ambnews.network;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import vn.allmobile.ambnews.activities.sflash.SFlashActivity.preloadData;
import vn.allmobile.ambnews.customview.LoadingDialog;
import vn.allmobile.ambnews.data.Article;
import vn.allmobile.ambnews.data.DbHelper;
import vn.allmobile.ambnews.data.Paper;
import vn.allmobile.ambnews.data.Province;
import vn.allmobile.ambnews.data.Weather;
import vn.allmobile.ambnews.utils.GlobalApplication;
import vn.allmobile.ambnews.utils.Log;

import android.app.ProgressDialog;

public class NetworkAPI {
	
	
	protected static NetworkAPI _instance;
	public static int _currentPaperIndex;
	public static String _currentPaperId;
	public static int _currentCategoryIndex;
	public static String _currentCategoryId;
	public static ProgressDialog _progressDiag;
	public static  List<Paper> _papers;
	public static Map<String, Paper> _papersMap;
	public static  List<Paper> _userListPapers;
	public static List<Article> _listArticles;
	public static List<Article> _listHotArticles;
	public static Weather _currentWeather;
	public static List<Province> _provinces;
	public static int _currentCategoryPage= 0;
	public static int isListRefresh = 0;
	public static long _syncTime = 15; // default 15 minutes
	public static String _lastNotificationId = "";
	public static String _appState = ""; 
	public static Boolean _isPaperUpdated = false;
	public static DbHelper _dbHelper;
	public static List<String> _imageList = new ArrayList<String>();
		
	public LoaderThread _loaderThread;
	public Thread _synchornizeThread;
	public preloadData _preloadData = null;
	
	private static int _loadMsg = -1;
	//private static Object _loadMsg = new Object();
	//public SynchronizeThead _syncThread;
	public static boolean _readySync = false;;
	public static boolean _fromNotification = false;
	
	public NetworkAPI() {
		// TODO Auto-generated constructor stub
	}
	
	public static NetworkAPI _()
	{
		if(_instance == null)
		{
			_instance = new NetworkAPI();
			_instance.connect();
		}
		return _instance;
		
	}
	
	
	 private void connect() {
		// TODO Auto-generated method stub
		this._loaderThread = new LoaderThread();
		this._loaderThread.start();
		//this._syncThread = new SynchronizeThead();
		//this._syncThread.start();
		//
	}

	 
	public  static  void onSetRequest(int paramInt) {	
		 synchronized (NetworkAPI.class) {
			// Log.v("loadMsg:" + paramInt);
			 _loadMsg = paramInt;	
		}			
	} 
	
	public  static int getSetRequest() {		
		synchronized (NetworkAPI.class) {
			//Log.v("loadMsg return:" + _loadMsg);
			int oldLoadMsg = _loadMsg;
			onSetRequest(-1);
			return  oldLoadMsg;	
		}
	}
}
